home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / bin / apxs < prev    next >
Encoding:
Text File  |  2001-03-06  |  20.4 KB  |  659 lines

  1. #!/usr/bin/perl
  2. ## ====================================================================
  3. ## The Apache Software License, Version 1.1
  4. ##
  5. ## Copyright (c) 2000 The Apache Software Foundation.  All rights
  6. ## reserved.
  7. ##
  8. ## Redistribution and use in source and binary forms, with or without
  9. ## modification, are permitted provided that the following conditions
  10. ## are met:
  11. ##
  12. ## 1. Redistributions of source code must retain the above copyright
  13. ##    notice, this list of conditions and the following disclaimer.
  14. ##
  15. ## 2. Redistributions in binary form must reproduce the above copyright
  16. ##    notice, this list of conditions and the following disclaimer in
  17. ##    the documentation and/or other materials provided with the
  18. ##    distribution.
  19. ##
  20. ## 3. The end-user documentation included with the redistribution,
  21. ##    if any, must include the following acknowledgment:
  22. ##       "This product includes software developed by the
  23. ##        Apache Software Foundation (http://www.apache.org/)."
  24. ##    Alternately, this acknowledgment may appear in the software itself,
  25. ##    if and wherever such third-party acknowledgments normally appear.
  26. ##
  27. ## 4. The names "Apache" and "Apache Software Foundation" must
  28. ##    not be used to endorse or promote products derived from this
  29. ##    software without prior written permission. For written
  30. ##    permission, please contact apache@apache.org.
  31. ##
  32. ## 5. Products derived from this software may not be called "Apache",
  33. ##    nor may "Apache" appear in their name, without prior written
  34. ##    permission of the Apache Software Foundation.
  35. ##
  36. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. ## DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. ## SUCH DAMAGE.
  48. ## ====================================================================
  49. ##
  50. ## This software consists of voluntary contributions made by many
  51. ## individuals on behalf of the Apache Software Foundation.  For more
  52. ## information on the Apache Software Foundation, please see
  53. ## <http://www.apache.org/>.
  54. ##
  55. ## Portions of this software are based upon public domain software
  56. ## originally written at the National Center for Supercomputing Applications,
  57. ## University of Illinois, Urbana-Champaign.
  58. ##
  59. ##
  60.  
  61. ##
  62. ##  apxs -- APache eXtenSion tool
  63. ##  Written by Ralf S. Engelschall <rse@apache.org>
  64. ##
  65.  
  66. require 5.003;
  67. use strict;
  68. package apxs;
  69.  
  70. ##
  71. ##  Configuration
  72. ##
  73.  
  74. my $CFG_TARGET        = q(httpd);            # substituted via Makefile.tmpl 
  75. my $CFG_CC            = q(m68k-unknown-amigaos-gcc);                # substituted via Makefile.tmpl
  76. my $CFG_CFLAGS        = q(-mstackextend -O3 -Dfork=vfork -m68060 -resident32 -mstackextend -Dfork=vfork -I/vol/compile/cross/php4/php-4.0.4pl1-amiga -I/vol/compile/cross/php4/php-4.0.4pl1-amiga/main -I/vol/compile/cross/php4/php-4.0.4pl1-build-68060/main -I/vol/compile/cross/php4/php-4.0.4pl1-amiga/Zend -I/vol/compile/cross/php4/php-4.0.4pl1-build-68060/Zend -I/vol/compile/cross/php4/php-4.0.4pl1-build-68060/TSRM -I/vol/compile/cross/php4/php-4.0.4pl1-amiga/TSRM -I/vol/compile/cross/php4/php-4.0.4pl1-build-68060 -DUSE_EXPAT -I../lib/expat-lite -DNO_DL_NEEDED `../apaci`);            # substituted via Makefile.tmpl
  77. my $CFG_CFLAGS_SHLIB  = q();      # substituted via Makefile.tmpl
  78. my $CFG_LD_SHLIB      = q();          # substituted via Makefile.tmpl
  79. my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpl 
  80. my $CFG_LIBS_SHLIB    = q();        # substituted via Makefile.tmpl 
  81. my $CFG_PREFIX        = q(/Apache);            # substituted via APACI install
  82. my $CFG_SBINDIR       = q(/Apache/bin);           # substituted via APACI install
  83. my $CFG_INCLUDEDIR    = q(/Apache/include/apache);        # substituted via APACI install
  84. my $CFG_LIBEXECDIR    = q(/Apache/libexec);        # substituted via APACI install
  85. my $CFG_SYSCONFDIR    = q(/Apache/conf);        # substituted via APACI install
  86.  
  87. ##
  88. ##  Cleanup the above stuff
  89. ##
  90. $CFG_CFLAGS =~ s|^\s+||;
  91. $CFG_CFLAGS =~ s|\s+$||;
  92. $CFG_CFLAGS =~ s|\s+`.+apaci`||;
  93.  
  94. ##
  95. ##  parse argument line
  96. ##
  97.  
  98. #   defaults for parameters
  99. my $opt_n = '';
  100. my $opt_g = '';
  101. my $opt_c = 0;
  102. my $opt_o = '';
  103. my @opt_D = ();
  104. my @opt_I = ();
  105. my @opt_L = ();
  106. my @opt_l = ();
  107. my @opt_W = ();
  108. my @opt_S = ();
  109. my $opt_e = 0;
  110. my $opt_i = 0;
  111. my $opt_a = 0;
  112. my $opt_A = 0;
  113. my $opt_q = 0;
  114.  
  115. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  116. #   the "+" metacharater at the format string to allow a list to be build by
  117. #   subsequent occurance of the same option.
  118. sub Getopts {
  119.     my ($argumentative, @ARGV) = @_;
  120.     my (@args, $first, $rest, $pos);
  121.     my ($errs) = 0;
  122.     local ($_);
  123.     local ($[) = 0;
  124.  
  125.     @args = split( / */, $argumentative);
  126.     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  127.         ($first, $rest) = ($1,$2);
  128.         if ($_ =~ m|^--$|) {
  129.             shift(@ARGV);
  130.             last;
  131.         }
  132.         $pos = index($argumentative,$first);
  133.         if ($pos >= $[) {
  134.             if ($args[$pos+1] eq ':') {
  135.                 shift(@ARGV);
  136.                 if ($rest eq '') {
  137.                     unless (@ARGV) {
  138.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  139.                         ++$errs;
  140.                     }
  141.                     $rest = shift(@ARGV);
  142.                 }
  143.                 eval "\$opt_$first = \$rest;";
  144.             }
  145.             elsif ($args[$pos+1] eq '+') {
  146.                 shift(@ARGV);
  147.                 if ($rest eq '') {
  148.                     unless (@ARGV) {
  149.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  150.                         ++$errs;
  151.                     }
  152.                     $rest = shift(@ARGV);
  153.                 }
  154.                 eval "push(\@opt_$first, \$rest);";
  155.             }
  156.             else {
  157.                 eval "\$opt_$first = 1";
  158.                 if ($rest eq '') {
  159.                     shift(@ARGV);
  160.                 }
  161.                 else {
  162.                     $ARGV[0] = "-$rest";
  163.                 }
  164.             }
  165.         }
  166.         else {
  167.             print STDERR "apxs:Error: Unknown option: $first\n";
  168.             ++$errs;
  169.             if ($rest ne '') {
  170.                 $ARGV[0] = "-$rest";
  171.             }
  172.             else {
  173.                 shift(@ARGV);
  174.             }
  175.         }
  176.     }
  177.     return ($errs == 0, @ARGV);
  178. }
  179.  
  180. sub usage {
  181.     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
  182.     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
  183.     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
  184.     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
  185.     print STDERR "               [-Wl,<flags>] <files> ...\n";
  186.     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  187.     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  188.     exit(1);
  189. }
  190.  
  191. #   option handling
  192. my $rc;
  193. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
  194. &usage if ($rc == 0);
  195. &usage if ($#ARGV == -1 and not $opt_g);
  196. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
  197.  
  198. #   argument handling
  199. my @args = @ARGV;
  200. my $name = 'unknown';
  201. $name = $opt_n if ($opt_n ne '');
  202.  
  203. #   overriding of configuration variables
  204. if (@opt_S) {
  205.     my ($opt_S);
  206.     foreach $opt_S (@opt_S) {
  207.         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
  208.             my ($var, $val) = ($1, $2);
  209.             my $oldval = eval "\$CFG_$var";
  210.             unless ($var and $oldval) {
  211.                 print STDERR "apxs:Error: no config variable $var\n";
  212.                 &usage;
  213.             }
  214.             eval "\$CFG_${var}=\"${val}\"";
  215.         } else {
  216.             print STDERR "apxs:Error: malformatted -S option\n";
  217.             &usage;
  218.         }       
  219.     }
  220. }
  221.  
  222. ##
  223. ##  Initial DSO support check
  224. ##
  225. if (not -x "$CFG_SBINDIR/$CFG_TARGET") {
  226.     print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
  227.     exit(1);
  228. }
  229. if (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
  230.     print STDERR "apxs:Error: Sorry, no DSO support for Apache available\n";
  231.     print STDERR "apxs:Error: under your platform. Make sure the Apache\n";
  232.     print STDERR "apxs:Error: module mod_so is compiled into your server\n";
  233.     print STDERR "apxs:Error: binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
  234.     exit(1);
  235. }
  236.  
  237. ##
  238. ##  Operation
  239. ##
  240.  
  241. #   helper function for executing a list of
  242. #   system command with return code checks
  243. sub execute_cmds {
  244.     my (@cmds) = @_;
  245.     my ($cmd, $rc);
  246.  
  247.     foreach $cmd (@cmds) {
  248.         print STDERR "$cmd\n";
  249.         $rc = system("$cmd");
  250.         if ($rc != 0) {
  251.             printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc >> 8);
  252.             exit(1);
  253.         }
  254.     }
  255. }
  256.  
  257. if ($opt_g) {
  258.     ##
  259.     ##  SAMPLE MODULE SOURCE GENERATION
  260.     ##
  261.  
  262.     if (-d $name) {
  263.         print STDERR "apxs:Error: Directory `$name' already exists. Remove it first\n";
  264.         exit(1);
  265.     }
  266.  
  267.     my $data = join('', <DATA>);
  268.     $data =~ s|%NAME%|$name|sg;
  269.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  270.  
  271.     my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
  272.  
  273.     print STDERR "Creating [DIR]  $name\n";
  274.     system("mkdir $name");
  275.     print STDERR "Creating [FILE] $name/Makefile\n";
  276.     open(FP, ">${name}/Makefile") || die;
  277.     print FP $mkf;
  278.     close(FP);
  279.     print STDERR "Creating [FILE] $name/mod_$name.c\n";
  280.     open(FP, ">${name}/mod_${name}.c") || die;
  281.     print FP $src;
  282.     close(FP);
  283.  
  284.     exit(0);
  285. }
  286.  
  287. if ($opt_q) {
  288.     ##
  289.     ##  QUERY INFORMATION 
  290.     ##
  291.  
  292.     my $result = '';
  293.     my $arg;
  294.     foreach $arg (@args) {
  295.         my $ok = 0;
  296.         my $name;
  297.         foreach $name (qw(
  298.             TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  299.             PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
  300.         )) {
  301.             if ($arg eq $name or $arg eq lc($name)) {
  302.                 my $val = eval "\$CFG_$name";
  303.                 $result .= "${val}##";
  304.                 $ok = 1;
  305.             }
  306.         }
  307.         if (not $ok) {
  308.             printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
  309.             exit(1);
  310.         }
  311.     }
  312.     $result =~ s|##$||;
  313.     $result =~ s|##| |g;
  314.     print $result;
  315. }
  316.  
  317. if ($opt_c) {
  318.     ##
  319.     ##  DSO COMPILATION
  320.     ##
  321.  
  322.     #   split files into sources and objects
  323.     my @srcs = ();
  324.     my @objs = ();
  325.     my $f;
  326.     foreach $f (@args) {
  327.         if ($f =~ m|\.c$|) {
  328.             push(@srcs, $f);
  329.         }
  330.         else {
  331.             push(@objs, $f);
  332.         }
  333.     }
  334.  
  335.     #   determine output file
  336.     my $dso_file;
  337.     if ($opt_o eq '') {
  338.         if ($#srcs > -1) {
  339.             $dso_file = $srcs[0];
  340.             $dso_file =~ s|\.[^.]+$|.so|;
  341.         }
  342.         elsif ($#objs > -1) {
  343.             $dso_file = $objs[0];
  344.             $dso_file =~ s|\.[^.]+$|.so|;
  345.         }
  346.         else {
  347.             $dso_file = "mod_unknown.so";
  348.         }
  349.     }
  350.     else {
  351.         $dso_file = $opt_o;
  352.     }
  353.  
  354.     #   create compilation commands
  355.     my @cmds = ();
  356.     my $opt = '';
  357.     my ($opt_Wc, $opt_I, $opt_D);
  358.     foreach $opt_Wc (@opt_W) {
  359.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  360.     }
  361.     foreach $opt_I (@opt_I) {
  362.         $opt .= "-I$opt_I ";
  363.     }
  364.     foreach $opt_D (@opt_D) {
  365.         $opt .= "-D$opt_D ";
  366.     }
  367.     my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
  368.     my $s;
  369.     foreach $s (@srcs) {
  370.         my $o = $s;
  371.         $o =~ s|\.c$|.o|;
  372.         $o =~ s|^.*/||;
  373.         push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
  374.         unshift(@objs, $o);
  375.     }
  376.  
  377.     #   create link command
  378.     my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
  379.     my $o;
  380.     foreach $o (@objs) {
  381.         $cmd .= " $o";
  382.     }
  383.     $opt = '';
  384.     my ($opt_Wl, $opt_L, $opt_l);
  385.     foreach $opt_Wl (@opt_W) {
  386.         if ($CFG_LD_SHLIB !~ m/gcc$/) {
  387.             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  388.         } else {
  389.             $opt .= " -W$opt_Wl";
  390.         }
  391.     }
  392.     foreach $opt_L (@opt_L) {
  393.         $opt .= " -L$opt_L";
  394.     }
  395.     foreach $opt_l (@opt_l) {
  396.         $opt .= " -l$opt_l";
  397.     }
  398.     $cmd .= $opt;
  399.     $cmd .= " $CFG_LIBS_SHLIB";
  400.     push(@cmds, $cmd);
  401.  
  402.     #   execute the commands
  403.     &execute_cmds(@cmds);
  404.  
  405.     #   allow one-step compilation and installation
  406.     if ($opt_i or $opt_e) {
  407.         @args = ($dso_file);
  408.     }
  409. }
  410.  
  411. if ($opt_i or $opt_e) {
  412.     ##
  413.     ##  DSO INSTALLATION
  414.     ##
  415.  
  416.     #   determine installation commands
  417.     #   and corresponding LoadModule/AddModule directives
  418.     my @lmd = ();
  419.     my @amd = ();
  420.     my @cmds = ();
  421.     my $f;
  422.     foreach $f (@args) {
  423.         if ($f !~ m|\.so$|) {
  424.             print STDERR "apxs:Error: file $f is not a DSO\n";
  425.             exit(1);
  426.         }
  427.         my $t = $f;
  428.         $t =~ s|^.+/([^/]+)$|$1|;
  429.         if ($opt_i) {
  430.             push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
  431.             push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  432.         }
  433.  
  434.         #   determine module symbolname and filename
  435.         my $filename = '';
  436.         if ($name eq 'unknown') {
  437.             $name = '';
  438.             my $base = $f;
  439.             $base =~ s|\.[^.]+$||;
  440.             if (-f "$base.c") {
  441.                 open(FP, "<$base.c");
  442.                 my $content = join('', <FP>);
  443.                 close(FP);
  444.                 if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  445.                     $name = "$1";
  446.                     $filename = "$base.c";
  447.                     $filename =~ s|^[^/]+/||;
  448.                 }
  449.             }
  450.             if ($name eq '') {
  451.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  452.                     $name = "$1";
  453.                     $filename = $base;
  454.                     $filename =~ s|^[^/]+/||;
  455.                 }
  456.             }
  457.             if ($name eq '') {
  458.                 print STDERR "apxs:Error: Sorry, cannot determine bootstrap symbol name.\n";
  459.                 print STDERR "apxs:Error: Please specify one with option `-n'.\n";
  460.                 exit(1);
  461.             }
  462.         }
  463.         if ($filename eq '') {
  464.             $filename = "mod_${name}.c";
  465.         }
  466.         my $dir = $CFG_LIBEXECDIR;
  467.         $dir =~ s|^$CFG_PREFIX/?||;
  468.         $dir =~ s|(.)$|$1/|;
  469.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  470.         push(@amd, sprintf("AddModule %s", $filename));
  471.     }
  472.  
  473.     #   execute the commands
  474.     &execute_cmds(@cmds);
  475.  
  476.     #   activate module via LoadModule/AddModule directive
  477.     if ($opt_a or $opt_A) {
  478.         if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
  479.             print STDERR "apxs:Error: Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found\n";
  480.             exit(1);
  481.         }
  482.  
  483.         open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
  484.         my $content = join('', <FP>);
  485.         close(FP);
  486.  
  487.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  488.             print STDERR "apxs:Error: Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.\n";
  489.             print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
  490.             exit(1);
  491.         }
  492.  
  493.         my $lmd;
  494.         my $c = '';
  495.         $c = '#' if ($opt_A);
  496.         foreach $lmd (@lmd) {
  497.             my $what = $opt_A ? "preparing" : "activating";
  498.             if ($content !~ m|\n#?\s*$lmd|) {
  499.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  500.             } else {
  501.                  $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
  502.             }
  503.             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  504.             print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
  505.         }
  506.         my $amd;
  507.         foreach $amd (@amd) {
  508.             if ($content !~ m|\n#?\s*$amd|) {
  509.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  510.             } else {
  511.                  $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
  512.             }
  513.         }
  514.         if (@lmd or @amd) {
  515.             if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
  516.                 print FP $content;
  517.                 close(FP);
  518.                 system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
  519.                        "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
  520.                        "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
  521.             } else {
  522.                 print STDERR "apxs:Error: unable to open configuration file\n";
  523.             }
  524.         }
  525.     }
  526. }
  527.  
  528. ##EOF##
  529. __DATA__
  530. ##
  531. ##  Makefile -- Build procedure for sample %NAME% Apache module
  532. ##  Autogenerated via ``apxs -n %NAME% -g''.
  533. ##
  534.  
  535. #   the used tools
  536. APXS=apxs
  537. APACHECTL=apachectl
  538.  
  539. #   additional user defines, includes and libraries
  540. #DEF=-Dmy_define=my_value
  541. #INC=-Imy/include/dir
  542. #LIB=-Lmy/lib/dir -lmylib
  543.  
  544. #   the default target
  545. all: mod_%NAME%.so
  546.  
  547. #   compile the DSO file
  548. mod_%NAME%.so: mod_%NAME%.c
  549.     $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
  550.  
  551. #   install the DSO file into the Apache installation
  552. #   and activate it in the Apache configuration
  553. install: all
  554.     $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
  555.  
  556. #   cleanup
  557. clean:
  558.     -rm -f mod_%NAME%.o mod_%NAME%.so
  559.  
  560. #   simple test
  561. test: reload
  562.     lynx -mime_header http://localhost/%NAME%
  563.  
  564. #   reload the module by installing and restarting Apache
  565. reload: install restart
  566.  
  567. #   the general Apache start/restart/stop procedures
  568. start:
  569.     $(APACHECTL) start
  570. restart:
  571.     $(APACHECTL) restart
  572. stop:
  573.     $(APACHECTL) stop
  574.  
  575. -=#=-
  576. /* 
  577. **  mod_%NAME%.c -- Apache sample %NAME% module
  578. **  [Autogenerated via ``apxs -n %NAME% -g'']
  579. **
  580. **  To play with this sample module, first compile it into a
  581. **  DSO file and install it into Apache's libexec directory 
  582. **  by running:
  583. **
  584. **    $ apxs -c -i mod_%NAME%.c
  585. **
  586. **  Then activate it in Apache's %TARGET%.conf file, for instance
  587. **  for the URL /%NAME%, as follows:
  588. **
  589. **    #   %TARGET%.conf
  590. **    LoadModule %NAME%_module libexec/mod_%NAME%.so
  591. **    <Location /%NAME%>
  592. **    SetHandler %NAME%
  593. **    </Location>
  594. **
  595. **  Then after restarting Apache via
  596. **
  597. **    $ apachectl restart
  598. **
  599. **  you immediately can request the URL /%NAME and watch for the
  600. **  output of this module. This can be achieved for instance via:
  601. **
  602. **    $ lynx -mime_header http://localhost/%NAME% 
  603. **
  604. **  The output should be similar to the following one:
  605. **
  606. **    HTTP/1.1 200 OK
  607. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  608. **    Server: Apache/1.3.4 (Unix)
  609. **    Connection: close
  610. **    Content-Type: text/html
  611. **  
  612. **    The sample page from mod_%NAME%.c
  613. */ 
  614.  
  615. #include "httpd.h"
  616. #include "http_config.h"
  617. #include "http_protocol.h"
  618. #include "ap_config.h"
  619.  
  620. /* The sample content handler */
  621. static int %NAME%_handler(request_rec *r)
  622. {
  623.     r->content_type = "text/html";      
  624.     ap_send_http_header(r);
  625.     if (!r->header_only)
  626.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  627.     return OK;
  628. }
  629.  
  630. /* Dispatch list of content handlers */
  631. static const handler_rec %NAME%_handlers[] = { 
  632.     { "%NAME%", %NAME%_handler }, 
  633.     { NULL, NULL }
  634. };
  635.  
  636. /* Dispatch list for API hooks */
  637. module MODULE_VAR_EXPORT %NAME%_module = {
  638.     STANDARD_MODULE_STUFF, 
  639.     NULL,                  /* module initializer                  */
  640.     NULL,                  /* create per-dir    config structures */
  641.     NULL,                  /* merge  per-dir    config structures */
  642.     NULL,                  /* create per-server config structures */
  643.     NULL,                  /* merge  per-server config structures */
  644.     NULL,                  /* table of config file commands       */
  645.     %NAME%_handlers,       /* [#8] MIME-typed-dispatched handlers */
  646.     NULL,                  /* [#1] URI to filename translation    */
  647.     NULL,                  /* [#4] validate user id from request  */
  648.     NULL,                  /* [#5] check if the user is ok _here_ */
  649.     NULL,                  /* [#3] check access by host address   */
  650.     NULL,                  /* [#6] determine MIME type            */
  651.     NULL,                  /* [#7] pre-run fixups                 */
  652.     NULL,                  /* [#9] log a transaction              */
  653.     NULL,                  /* [#2] header parser                  */
  654.     NULL,                  /* child_init                          */
  655.     NULL,                  /* child_exit                          */
  656.     NULL                   /* [#0] post read-request              */
  657. };
  658.  
  659.